menu = {
    '北京': {
        '海淀': {
            '五道口': {
                '搜狐': {},
                '网易': {},
                '快手': {}
            },
            '中关村': {
                '爱奇艺': {},
                '汽车之家': {},
                '优酷': {},
            },
            '上地': {
                '百度': {},
                '小米': {},
            },
        },
        '昌平': {
            '沙河': {
                '阿泰包子': {},
                '北航': {},
            },
            '天通苑': {},
            '回龙观': {},
        },
        '朝阳': {},
        '东城': {},
    },
    '上海': {
        '闵行': {
            "人民广场": {
                '炸鸡店': {}
            }
        },
        '闸北': {
            '火车站': {
                '携程': {}
            }
        },
        '浦东': {},
    },
    '山东': {},
}

# 输入b或者B返回上一级菜单。
# 输入q或者Q结束程序。
# stack   后进先出

# stack = []
# 入栈
# stack.append('a')
# stack.append('b')
# stack.append('c')
# print(stack)
# res = stack.pop()
# print(res, stack)
# res = stack.pop()
# print(res, stack)
# res = stack.pop()
# print(res, stack)

stack = [
    menu,
    # menu['北京'],
    # menu['北京']['海淀'],
    # menu['北京']['海淀']['五道口'],
    # menu['北京']['海淀']['五道口']['搜狐']
]
while stack:
    for k in stack[-1]:
        print(k)
    choice = input('>>>: ').strip()  # 北京
    if choice in stack[-1]:  # stack[-1] --> menu
        next_layer = stack[-1][choice]
        stack.append(next_layer)
    elif choice.upper() == "Q":
        break
    elif choice.upper() == "B":
        stack.pop()
